﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class fInHoaDon : Form
    {
        public fInHoaDon()
        {
            InitializeComponent();
        }

        #region Variable
        private string phong;
        private string dongia;
        private string thanhtien;
        private string ngaythue;
        private string ngaytra;
        private string songay;
        private List<string> lstr_stt = new List<string>();
        private List<string> lstr_khachhang = new List<string>();
        private List<string> lstr_loaikhach = new List<string>();
        private List<string> lstr_cmnd = new List<string>();
        private List<string> lstr_diachi = new List<string>();
        private List<string> tatcakh = new List<string>();
        #endregion

        #region Properties
        public string Phong
        {
            get { return phong; }
            set { phong = value; }
        }
        public string Dongia
        {
            get { return dongia; }
            set { dongia = value; }
        }
        public string Thanhtien
        {
            get { return thanhtien; }
            set { thanhtien = value; }
        }
        public string Ngaythue
        {
            get { return ngaythue; }
            set { ngaythue = value; }
        }
        public string Ngaytra
        {
            get { return ngaytra; }
            set { ngaytra = value; }
        }
        public string Songay
        {
            get { return songay; }
            set { songay = value; }
        }
        public List<string> Tatcakh
        {
            get { return tatcakh; }
            set { tatcakh = value; }
        }
        public List<string> Lstr_stt
        {
            get { return lstr_stt; }
            set { lstr_stt = value; }
        }
        public List<string> Lstr_khachhang
        {
            get { return lstr_khachhang; }
            set { lstr_khachhang = value; }
        }
        public List<string> Lstr_loaikhach
        {
            get { return lstr_loaikhach; }
            set { lstr_loaikhach = value; }
        }
        public List<string> Lstr_cmnd
        {
            get { return lstr_cmnd; }
            set { lstr_cmnd = value; }
        }
        public List<string> Lstr_diachi
        {
            get { return lstr_diachi; }
            set { lstr_diachi = value; }
        }
        #endregion

        /// <summary>
        /// Hiển thị trang in với đầy đủ thông tin phòng, ngày thuê, khách hàng
        /// kiểm tra người dùng đăng nhập chưa, nếu đăng nhập rồi thì cho phép thao tác, nếu chưa thì không cho phép thao tác
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fInHoaDon_Load(object sender, EventArgs e)
        {
            labelphong.Text = phong;
            labeldongia.Text = dongia;
            labelthanhtien.Text = thanhtien;
            labelngaybatdau.Text = ngaythue;
            labelngaytra.Text = ngaytra;
            labelsongay.Text = songay;
            XuLyInHoaDon xlihd = new XuLyInHoaDon();
            xlihd.Tatcakh = tatcakh;
            xlihd.XuLyHienThi();
            lstr_khachhang = xlihd.Lstr_khachhang;
            lstr_loaikhach = xlihd.Lstr_loaikhach;
            lstr_cmnd = xlihd.Lstr_cmnd;
            lstr_diachi = xlihd.Lstr_diachi;
            for (int i = 0; i < tatcakh.Count; i++)
            {
                if (i == 0)
                {
                    textBoxstt1.Text = "1";
                    textBoxkh1.Text = lstr_khachhang[i];
                    textBoxlk1.Text = lstr_loaikhach[i];
                    textBoxcm1.Text = lstr_cmnd[i];
                    textBoxdc1.Text = lstr_diachi[i];
                }
                if (i == 1)
                {
                    textBoxstt2.Text = "2";
                    textBoxkh2.Text = lstr_khachhang[i];
                    textBoxlk2.Text = lstr_loaikhach[i];
                    textBoxcm2.Text = lstr_cmnd[i];
                    textBoxdc2.Text = lstr_diachi[i];
                }
                if (i == 2)
                {
                    textBoxstt3.Text = "3";
                    textBoxkh3.Text = lstr_khachhang[i];
                    textBoxlk3.Text = lstr_loaikhach[i];
                    textBoxcm3.Text = lstr_cmnd[i];
                    textBoxdc3.Text = lstr_diachi[i];
                }
                if (i == 3)
                {
                    textBoxstt4.Text = "4";
                    textBoxkh4.Text = lstr_khachhang[i];
                    textBoxlk4.Text = lstr_loaikhach[i];
                    textBoxcm4.Text = lstr_cmnd[i];
                    textBoxdc4.Text = lstr_diachi[i];
                }
                if (i == 4)
                {
                    textBoxstt5.Text = "5";
                    textBoxkh5.Text = lstr_khachhang[i];
                    textBoxlk5.Text = lstr_loaikhach[i];
                    textBoxcm5.Text = lstr_cmnd[i];
                    textBoxdc5.Text = lstr_diachi[i];
                }
                if (i == 5)
                {
                    textBoxstt6.Text = "6";
                    textBoxkh6.Text = lstr_khachhang[i];
                    textBoxlk6.Text = lstr_loaikhach[i];
                    textBoxcm6.Text = lstr_cmnd[i];
                    textBoxdc6.Text = lstr_diachi[i];
                }
                if (i == 6)
                {
                    textBoxstt7.Text = "7";
                    textBoxkh7.Text = lstr_khachhang[i];
                    textBoxlk7.Text = lstr_loaikhach[i];
                    textBoxcm7.Text = lstr_cmnd[i];
                    textBoxdc7.Text = lstr_diachi[i];
                }
            }
        }

        /// <summary>
        /// Tạo ảnh trang in sau đó mở hộp thoại Print (cho phép chọn máy in, tùy chọn trang in,…)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btin_Click(object sender, EventArgs e)
        {
            CaptureScreen();
            printDialog1.AllowSomePages = true;
            printDialog1.ShowHelp = true;
            printDialog1.Document = printDocument1;
            DialogResult result = printDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                printDocument1.Print();
            }
        }

        /// <summary>
        /// Lấy ảnh trang in
        /// </summary>
        private void CaptureScreen()
        {
            Graphics myGraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            memoryGraphics.CopyFromScreen(
                this.Location.X, this.Location.Y, 0, 0, s);
        }

        Bitmap memoryImage;

        /// <summary>
        /// Tạo ảnh trang in
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }
    }
}
